<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/4/23
 * Time: 15:19
 */

namespace app\logic\index\font;


use app\logic\BaseLogic;

class FontLogic extends BaseLogic
{
    protected $model;

    protected static $instance;

    public function __construct()
    {
        parent::__construct();
        $this->model = \app\model\font\FontModel::getInstance();
    }

    public static function getInstance()
    {
//        if(is_object(self::$instance)){
//            return self::$instance;
//        }

        return  new self();
    }

    public function getList($param)
    {
        $where = [
            'isdel'=>0,
            'status'=>1,
        ];
        if(!empty($param['lang'])){
            $where['lang'] = $param['lang'];
        }else{
            $where['lang'] = '中文';
        }

        $fields = ['id','name','icon','filename','lang'];
        $order = ['created_at', 'asc'];

        $list =  $this->model->index($where, $fields, $order);
        $data = $list['data']->toArray();

        //默认选择放在首位
        $firsts = [];
        foreach($data as $k=>$val){
            if(!empty($param['selected_id']) && $val['id']==$param['selected_id']){
                $firsts = $val;
                unset($data[$k]);
            }
        }
        $data = array_values($data);
        $firsts && array_unshift($data,$firsts);
        $list['data'] = $data;

        return $list;
    }
}